<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
get_config_keytable("workclass_admin");
empty($do) && $do = 'list';
if ($do == 'list') {
	//列表信息 
	$wheresql = '';
	$page = max(1, getGP('page','G','int'));
	$pagesize = $_CONFIG->config_data('pagenum');
	$offset = ($page - 1) * $pagesize;
	$url = 'admin.php?ac=template&fileurl=work';
	if (user_union_id!='') {
		$wheresql .= " AND unionid='".user_union_id."'";
	}else{
		$wheresql .= " AND unionid='".union_id."'";
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."workclass_template WHERE 1 $wheresql");
    $sql = "SELECT * FROM ".DB_TABLEPRE."workclass_template WHERE 1 $wheresql ORDER BY id desc LIMIT $offset, $pagesize";
	$result = $db->fetch_all($sql);
	include_once('template/template.php');

} elseif ($do == 'update') {
	get_union_add();
	$idarr = getGP('id','P','array');
	foreach ($idarr as $id) {
		$db->query("DELETE FROM ".DB_TABLEPRE."workclass_template WHERE id = '$id'");
		$db->query("DELETE FROM ".DB_TABLEPRE."workclass_flow WHERE template_id= '$id'");
		$db->query("DELETE FROM ".DB_TABLEPRE."workclass_form WHERE template_id= '$id'");
		$content=$id;
		$title='删除工作流模板';
		get_oa_log_dbadd($id,$content,$title,35,$_USER->id);	
	}
	show_msg('工作流模板删除成功！', 'admin.php?ac=template&fileurl=work');

}elseif ($do == 'add') {
	get_union_add();
	include_once('template/template_add.php');
}elseif ($do == 'addsave') {
	get_union_add();
	$title = getGP('title','P');
	$workclasstype = getGP('workclasstype','P');
	$tempkey = getGP('tempkey','P');
	$temptype = '2';
	if(getGP('workuse','P')!=''){
		$workuse = getGP('workuse','P');
	}else{
		$workuse = '0';
	}
	$workmonitor = getGP('workmonitor','P');
	if(getGP('workadmin','P')!=''){
	$workadmin = getGP('workadmin','P');
	}else{
	$workadmin = '0';
	}
	$uid = $_USER->id;
	$date=get_date('Y-m-d H:i:s',PHP_TIME);
	if($tempkey=='3'){
		$tmpytpe = 2;
	}else{
		$tmpytpe = getGP('tmpytpe','P');
	}
	$tmpaddr = getGP('tmpaddr','P');
	//主表信息
	$workclass_template = array(
		'title' => $title,
		'workclasstype' => $workclasstype,
		'tempkey' => $tempkey,
		'temptype' => $temptype,
		'workuse' => $workuse,
		'workmonitor' => $workmonitor,
		'tmpytpe' => $tmpytpe,
		'tmpaddr' => $tmpaddr,
		'date' => $date,
		'uid' => $uid,
		'unionid' => union_id
	);
	//写入主表信息
	insert_db('workclass_template',$workclass_template);
	$id=$db->insert_id();
	$content=$title.get_inc_log(1).$workclasstype.get_inc_log(1).$tempkey.get_inc_log(1).$temptype.get_inc_log(1).$workuse.get_inc_log(1).$workmonitor.get_inc_log(1).$workadmin.get_inc_log(1).$date.get_inc_log(1).$uid;
	$title='添加工作流模板';
	get_oa_log_dbadd($id,$content,$title,35,$_USER->id);
	show_msg('工作流模板添加成功！', 'admin.php?ac=template&fileurl=work');
}elseif ($do == 'edit') {
	get_union_add();
	$id = getGP('id','G','int');
	$blog = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."workclass_template  WHERE id = '$id'");
	include_once('template/template_edit.php');
}elseif ($do == 'editsave') {
	get_union_add();
	$id = getGP('id','P','int');
	$title = getGP('title','P');
	$workclasstype = getGP('workclasstype','P');
	$tempkey = getGP('tempkey','P');
	$temptype = '2';
	if(getGP('workuse','P')!=''){
		$workuse = getGP('workuse','P');
	}else{
		$workuse = '0';
	}
	$workmonitor = getGP('workmonitor','P');
	if(getGP('workadmin','P')!=''){
		$workadmin = getGP('workadmin','P');
	}else{
		$workadmin = '0';
	}
	if($tempkey=='3'){
		$tmpytpe = 2;
	}else{
		$tmpytpe = getGP('tmpytpe','P');
	}
	$tmpaddr = getGP('tmpaddr','P');
	//主表信息
	$workclass_template = array(
		'title' => $title,
		'workclasstype' => $workclasstype,
		'tempkey' => $tempkey,
		'workuse' => $workuse,
		'tmpytpe' => $tmpytpe,
		'tmpaddr' => $tmpaddr,
		'workmonitor' => $workmonitor
	);
	update_db('workclass_template',$workclass_template, array('id' => $id));
	$workclass_form = array(
		'type_id' => $workclasstype
	);
	update_db('workclass_form',$workclass_form, array('template_id' => $id));
	$workclass_flow = array(
		'type_id' => $workclasstype
	);
	update_db('workclass_flow',$workclass_flow, array('template_id' => $id));
	$content=$title.get_inc_log(1).$workclasstype.get_inc_log(1).$tempkey.get_inc_log(1).$temptype.get_inc_log(1).$workuse.get_inc_log(1).$workmonitor.get_inc_log(1).$workadmin;
	$title='编辑工作流模板';
	get_oa_log_dbadd($id,$content,$title,35,$_USER->id);
	show_msg('工作流模板修改成功！', 'admin.php?ac=template&fileurl=work');
}
?>